package com.qf.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.pojo.User;
import com.qf.service.Userserviceimpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author jiangjingbo
 * @version V1.0
 * @Project java2203
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/6/30 20:07
 */

//以json数据进行返回
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private Userserviceimpl userserviceimpl;

    /**
     * 产看所有用户
     * @return
     */
    @GetMapping("/userall")
    public Object userall(){
        List<User> users = userserviceimpl.findallService();
        return users;
    }

    /**
     * 查看分页
     */
    @GetMapping("pageuserall")
    public Object pageuserall(){
        Page<Object> objects = PageHelper.startPage(1, 3);
        List<User> users = userserviceimpl.findpageUserall();
        PageInfo<User> objectPageInfo = new PageInfo<User>(users);
        return objectPageInfo;
    }

    /**
     * 根据id
     */
    @GetMapping("findUserid")
    public Object finduserid(int id){
        User userid = userserviceimpl.findUserid(id);
        return userid;
    }
    /**
     * 添加用户
     */
    @GetMapping("/addUser")
    public  Object addUser(@RequestBody User user){
        int i = userserviceimpl.addUSerService(user);
        return i;
    }

    @GetMapping("/updata")
    public  Object updata(@RequestBody User user){
        int i = userserviceimpl.updataUserservice(user);
        return i;
    }

    @GetMapping("/delete")
    public  Object delete(@RequestBody User user){
        Integer id = user.getId();
        int i = userserviceimpl.deleteUserservice(id);
        return i;
    }

}
